// 地址相关API调用 - 与后端AddressController接口保持一致

import request from '@/utils/request'

// 地址数据类型定义（与后端AddressVO对应）
export interface AddressVO {
  id: string
  name: string
  phone: string
  province: string
  city: string
  district: string
  street: string
  detail: string
  fullAddress: string
  postcode?: string
  isDefault: boolean
  tag?: string
  createdTime: string
  updatedTime: string
}

// 添加地址请求类型（与后端AddressAddRequest对应）
export interface AddressAddRequest {
  name: string
  phone: string
  province: string
  city: string
  district: string
  street?: string
  detail: string
  postcode?: string
  isDefault?: boolean
  tag?: string
}

// 更新地址请求类型（与后端AddressUpdateRequest对应）
export interface AddressUpdateRequest {
  id: string
  name: string
  phone: string
  province: string
  city: string
  district: string
  street?: string
  detail: string
  postcode?: string
  isDefault?: boolean
  tag?: string
}

// 添加地址
export const addAddress = (data: AddressAddRequest) => {
  return request.post<string>('/api/address/add', data)
}

// 更新地址
export const updateAddress = (data: AddressUpdateRequest) => {
  return request.put<boolean>('/api/address/update', data)
}

// 删除地址
export const deleteAddress = (addressId: string) => {
  return request.delete<boolean>(`/api/address/delete/${addressId}`)
}

// 获取用户所有地址
export const getUserAddresses = () => {
  return request.get<AddressVO[]>('/api/address/list')
}

// 获取特定地址
export const getAddressById = (addressId: string) => {
  return request.get<AddressVO>(`/api/address/get/${addressId}`)
}

// 获取默认地址
export const getDefaultAddress = () => {
  return request.get<AddressVO>('/api/address/get/default')
}

// 设置默认地址
export const setDefaultAddress = (addressId: string) => {
  return request.put<boolean>(`/api/address/default/${addressId}`)
} 